/* threadpool.h */

#ifndef _THREADPOOL_H_
#define _THREADPOOL_H_

#include <pthread.h>
#include <semaphore.h>
#define MAX_NUM_JOB 20

//define the Job node
typedef struct Thread_Job
{
    unsigned char * head;
    char * mailtmpsave;
    unsigned int mailsize;
}threadjob;

typedef struct Job_Queue_Control
{
    int readpos;
    int writepos;
    int jobcount;
}jobqueuectl;

//define the ThreadPool
typedef struct Thread_Pool
{
	pthread_t * threadidarr;	 //the array of record every threads' id
	int max_thread_num;          //the max num of thread
	pthread_mutex_t queue_lock;
    sem_t * sem_arr;
	int shutdown;                //1-close 0-open
}thpool;

//functions for ThreadPool
int Theadpool_create(int threadN);	//create the threadpool
//add job to Queue
int Threadpool_add_job(void *arg);
//destroy the threadpool
int Threadpool_destroy(void);	
//thread do the job
void Thread_do_job(int threadno);
//print for test
int PrintJobs(void);

#endif
